package CalculateSystem;

import java.util.Scanner;

import CalculateSystem.CalculateMassage.CalculateMassage;
import SpaceDebug.DebugTool.DebugTool;
import SpaceDebug.Factory.DebugFactory.DebugFactory;
import SpaceDebug.IOTool.Write.WriteType;

public class CalculateMain {
    int tempValue = 0;
    DebugTool debugTool = DebugFactory.GetTool(WriteType.DebugMassage);
    CalculateMassage massage = new CalculateMassage();

    public int Add(int a, int b) {
        return a + b;
    }

    public int Subtract(int a, int b) {
        return a - b;
    }

    public int Multiply(int a, int b) {
        return a * b;
    }

    public int Division(int a, int b) throws Exception {
        if (b == 0) {
            debugTool.Error(massage.setAddedInfo("除以0"));
        }
        return a / b;
    }

    /**
     * 输入格式 数字 空格 运算符 空格 数字
     * 因为不想花更多时间在这个上面
     * 理解万岁😋
     * 
     * @return
     * @throws Exception
     */
    public int Input() throws Exception {
        int reSult = 0;
        Scanner scan = new Scanner(System.in);
        String read = scan.nextLine();
        massage.setInputMassage(read);
        String[] Strings = read.split(" ");
        if (Strings.length != 3)
            debugTool.Error(massage.setAddedInfo("输入格式错误，字符串截取不等于三"));
        try {
            int left = Integer.parseInt(Strings[0]);
            int right = Integer.parseInt(Strings[2]);
            switch (Strings[1]) {
                case "+":
                    reSult = Add(left, right);
                    break;
                case "-":
                    reSult = Subtract(left, right);
                    break;
                case "*":
                    reSult = Multiply(left, right);
                    break;
                case "/":
                    reSult = Division(left, right);
                    break;
                default:
                    debugTool.Error(massage.setAddedInfo("输入格式错误:未定义符号"));
                    break;
            }
        } catch (Exception e) {
            debugTool.Error(massage.setAddedInfo("输入格式错误:非数字输入"));
        }
        debugTool.Info(massage.setAddedInfo("结果:" + reSult));
        return reSult;
    }
}
